import {
	defineStore,
} from 'pinia';
import {
	ref,
} from 'vue';

// 创建聊天室仓库
const chatRoomStore = defineStore(
	'chatroom',
	() => {
		// 定义聊天室数组
		const chatRooms = ref();

		// 添加聊天室
		const addChatRoom = (room) => {
			chatRooms.value = room;
		};

		// 清理聊天室信息
		const clearChatRooms = () => {
			chatRooms.value = [];
		};

		return {
			chatRooms,
			addChatRoom,
			clearChatRooms,
		};
	},
	// 网页端配置
	// persist: true,
	// 小程序端配置
	{
		persist: {
			storage: {
				getItem(key) {
					return uni.getStorageSync(key);
				},
				setItem(key, value) {
					uni.setStorageSync(key, value);
				},
			},
		},
	}
);

// 暴露用户小仓库
export default chatRoomStore;
